package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BlogDetails;
import com.ruoyi.system.service.IBlogDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章管理Controller
 * 
 * @author ruoyi
 * @date 2024-06-22
 */
@RestController
@RequestMapping("/system/details")
public class BlogDetailsController extends BaseController
{
    @Autowired
    private IBlogDetailsService blogDetailsService;

    /**
     * 查询文章管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogDetails blogDetails)
    {
        startPage();
        List<BlogDetails> list = blogDetailsService.selectBlogDetailsList(blogDetails);
        return getDataTable(list);
    }

    /**
     * 导出文章管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:details:export')")

    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogDetails blogDetails)
    {
        List<BlogDetails> list = blogDetailsService.selectBlogDetailsList(blogDetails);
        ExcelUtil<BlogDetails> util = new ExcelUtil<BlogDetails>(BlogDetails.class);
        util.exportExcel(response, list, "文章管理数据");
    }

    /**
     * 获取文章管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:details:query')")
    @GetMapping(value = "/{blogId}")
    public AjaxResult getInfo(@PathVariable("blogId") Long blogId)
    {
        return success(blogDetailsService.selectBlogDetailsByBlogId(blogId));
    }

    /**
     * 新增文章管理
     */
    @PreAuthorize("@ss.hasPermi('system:details:add')")

    @PostMapping
    public AjaxResult add(@RequestBody BlogDetails blogDetails)
    {
        return toAjax(blogDetailsService.insertBlogDetails(blogDetails));
    }

    /**
     * 修改文章管理
     */
    @PreAuthorize("@ss.hasPermi('system:details:edit')")

    @PutMapping
    public AjaxResult edit(@RequestBody BlogDetails blogDetails)
    {
        return toAjax(blogDetailsService.updateBlogDetails(blogDetails));
    }

    /**
     * 删除文章管理
     */
    @PreAuthorize("@ss.hasPermi('system:details:remove')")

	@DeleteMapping("/{blogIds}")
    public AjaxResult remove(@PathVariable Long[] blogIds)
    {
        return toAjax(blogDetailsService.deleteBlogDetailsByBlogIds(blogIds));
    }
}
